package Frame;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileSystemView;

import Function.FCAnimationLibrary;
import Function.FCItemLibrary;
import Function.FCMonsterLibrary;
import VWorldGameStudio.FCMonster;

/**
 * 编辑或新建怪物。
 */
public class FCEditMonster extends JDialog {
//
//	private JFileChooser filec = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()) {
//		protected javax.swing.JDialog createDialog(java.awt.Component parent) throws java.awt.HeadlessException {
//			JDialog jd = super.createDialog(parent);
//			jd.setSize(500, 400);
//			jd.setTitle("选择文件");
//			jd.setResizable(false);
//			jd.setLocationRelativeTo(null);
//			return jd;
//		};
//	};
//
//	private String[] shuxingstr = { "奖励金额", "怪物血量", "怪物防御", "闪避几率", "血量恢复", "奖励经验", "主炮防甲", "主对人伤", "主对车伤", "主破坏力",
//			"主穿甲值", "副炮防甲", "副对人伤", "副对车伤", "副破坏力", "副穿甲值",  "普对人伤", "普对车伤", "普破坏力", "普穿甲值", null, "酸抗性",
//			"麻痹抗性", "毒气抗性", "睡眠抗性", "冷冻抗性", "火焰抗性","速度"};
//
//	private JLabel[] name = new JLabel[shuxingstr.length];
//	private JTextField[] shuxing = new JTextField[shuxingstr.length];
//	// length = 4
//	private String[] type = { "bionic", "electron", "tank", "biochemistry" };
//	private int nowSelectId = 0;
//	public FCEditMonster(boolean isnew, FCMonsterLibrary monl, FCAnimationLibrary anil, FCItemLibrary itl) {
//
//		setTitle((isnew) ? "怪物管理-新增怪物" : "怪物管理-编辑怪物");
//		setBounds(0, 0, 615, 640);
//		setResizable(false);
//		setLayout(null);
//		setLocationRelativeTo(null);
//		setModal(true);
//
//		JLabel a = new JLabel("怪物ID");
//		a.setBounds(10, 10, 60, 20);
//		this.add(a);
//
//		JComboBox<String> a1 = new JComboBox<String>();
//		a1.setBounds(70, 10, 130, 20);
//		a1.setEnabled(!isnew);
//		if (isnew) {
//			a1.addItem(String.valueOf(monl.getMonsterNewID()));
//		} else {
//			for(String name: monl.monstername){
//				a1.addItem(name);
//			}
//		}
//		this.add(a1);
//
//		JLabel a2 = new JLabel("怪物名称");
//		a2.setBounds(210, 10, 60, 20);
//		this.add(a2);
//
//		JTextField a3 = new JTextField();
//		a3.setBounds(270, 10, 130, 20);
//		this.add(a3);
//
//		JLabel a4 = new JLabel("怪物种类");
//		a4.setBounds(410, 10, 60, 20);
//		this.add(a4);
//
//		JComboBox<String> a5 = new JComboBox<String>();
//		a5.setBounds(470, 10, 130, 20);
//		a5.addItem("仿生类");
//		a5.addItem("电子类");
//		a5.addItem("坦克类");
//		a5.addItem("生化类");
//		this.add(a5);
//
//		JLabel b = new JLabel();
//		b.setBounds(-1, 95, getWidth(), 60);
//		b.setBorder(BorderFactory.createLineBorder(Color.black));
//		this.add(b);
//
//		JLabel b1 = new JLabel();
//		b1.setBounds(-1, 154, getWidth(), 61);
//		b1.setBorder(BorderFactory.createLineBorder(Color.black));
//		this.add(b1);
//
//		JLabel b2 = new JLabel();
//		b2.setBounds(-1, 214, getWidth(), 61);
//		b2.setBorder(BorderFactory.createLineBorder(Color.black));
//		this.add(b2);
//
//		JLabel b3 = new JLabel();
//		b3.setBounds(-1, 274, getWidth(), 61);
//		b3.setBorder(BorderFactory.createLineBorder(Color.black));
//		this.add(b3);
//
//		int ii = 0;
//		for (int i = 0; i < shuxingstr.length; i++)
//			if (shuxingstr[i] != null) {
//				System.out.println(i);
//				name[ii] = new JLabel(shuxingstr[i]);
//				name[ii].setBounds(10 + 200 * (i % 3), 40 + 30 * (int) (i / 3), 60, 20);
//				this.add(name[ii]);
//				shuxing[ii] = new JTextField();
//				shuxing[ii].setBounds(70 + 200 * (i % 3), 40 + 30 * (int) (i / 3), 130, 20);
//				shuxing[ii].setText("0");
//				this.add(shuxing[ii]);
//				ii++;
//			}
//
//		JLabel c = new JLabel("触发几率");
//		c.setBounds(10, 340, 60, 20);
//		this.add(c);
//
//		JComboBox<String> c1 = new JComboBox<String>();
//		c1.setBounds(70, 340, 130, 20);
//		for (int i = 1; i < 11; i++) {
//			c1.addItem(String.valueOf(i));
//		}
//		this.add(c1);
//
//		JLabel d = new JLabel("主攻动画");
//		d.setBounds(10, 370, 60, 20);
//		this.add(d);
//
//		JComboBox<String> d1 = new JComboBox<String>();
//		d1.setBounds(70, 370, 130, 20);
//		d1.addItem("null");
//		for (int i = 0; i < anil.getAnimationNum(); i++) {
//			d1.addItem(anil.getIDOfNum(i));
//		}
//		this.add(d1);
//
//		JLabel e = new JLabel("副攻动画");
//		e.setBounds(10, 400, 60, 20);
//		this.add(e);
//
//		JComboBox<String> e1 = new JComboBox<String>();
//		e1.setBounds(70, 400, 130, 20);
//		e1.addItem("null");
//		for (int i = 0; i < anil.getAnimationNum(); i++)
//			e1.addItem(anil.getIDOfNum(i));
//		this.add(e1);
//
//		JLabel f = new JLabel("普攻动画");
//		f.setBounds(10, 430, 60, 20);
//		this.add(f);
//
//		JComboBox<String> f1 = new JComboBox<String>();
//		f1.setBounds(70, 430, 130, 20);
//		f1.addItem("null");
//		for (int i = 0; i < anil.getAnimationNum(); i++) {
//			f1.addItem(anil.getIDOfNum(i));
//		}
//		this.add(f1);
//
//		JLabel upgrade = new JLabel("变身下阶段");
//		upgrade.setBounds(10, 455, 150, 20);
//		this.add(upgrade);
//
//		JComboBox<String> upgrade1 = new JComboBox<String>();
//		upgrade1.setBounds(160, 455, 130, 20);
//		upgrade1.addItem("null");
//		for (int i = 0; i < monl.monstername.size(); i++) {
//			upgrade1.addItem(monl.monstername.get(i));
//		}
//		this.add(upgrade1);
//
//		JLabel keeptank = new JLabel("绑定坦克");
//		keeptank.setBounds(10, 475, 150, 20);
//		this.add(keeptank);
//
//		JComboBox<String> keeptank1 = new JComboBox<String>();
//		keeptank1.setBounds(160, 475, 130, 20);
//		keeptank1.addItem("null");
//		for (int i = 0; i < FCGMaster.tanksLibrary.getNewTankID(); i++) {
//			keeptank1.addItem(FCGMaster.tanksLibrary.getTankNameOfID(i));
//		}
//		this.add(keeptank1);
//
//		JLabel fightItem1 = new JLabel("战斗物品1");
//		fightItem1.setBounds(10, 495, 100, 20);
//		this.add(fightItem1);
//
//		JComboBox<String> fightItem1a = new JComboBox<String>();
//		fightItem1a.setBounds(110, 495, 130, 20);
//		fightItem1a.addItem("null");
//		for (int i = 0; i < itl.getItemNewID(); i++) {
//			fightItem1a.addItem(itl.getNameOfNum(i));
//		}
//		this.add(fightItem1a);
//
//		JLabel fightItem2= new JLabel("战斗物品2");
//		fightItem2.setBounds(260, 495, 100, 20);
//		this.add(fightItem2);
//
//		JComboBox<String> fightItem2a = new JComboBox<String>();
//		fightItem2a.setBounds(360, 495, 130, 20);
//		fightItem2a.addItem("null");
//		for (int i = 0; i < itl.getItemNewID(); i++) {
//			fightItem2a.addItem(itl.getNameOfNum(i));
//		}
//		this.add(fightItem2a);
//
//		JLabel fightItem3 = new JLabel("战斗物品3");
//		fightItem3.setBounds(10, 515, 100, 20);
//		this.add(fightItem3);
//		JComboBox<String> fightItem3a = new JComboBox<String>();
//		fightItem3a.setBounds(110, 515, 130, 20);
//		fightItem3a.addItem("null");
//		for (int i = 0; i < itl.getItemNewID(); i++) {
//			fightItem3a.addItem(itl.getNameOfNum(i));
//		}
//		this.add(fightItem3a);
//
//		JLabel fightItem4= new JLabel("战斗物品4");
//		fightItem4.setBounds(260, 515, 100, 20);
//		this.add(fightItem4);
//		JComboBox<String> fightItem4a = new JComboBox<String>();
//		fightItem4a.setBounds(360, 515, 130, 20);
//		fightItem4a.addItem("null");
//		for (int i = 0; i < itl.getItemNewID(); i++) {
//			fightItem4a.addItem(itl.getNameOfNum(i));
//		}
//		this.add(fightItem4a);
//
//		JLabel g = new JLabel("掉落物品");
//		g.setBounds(210, 340, 60, 20);
//		this.add(g);
//
//		JComboBox<String> g1 = new JComboBox<String>();
//		g1.setBounds(270, 340, 130, 20);
//		g1.addItem("null");
//		for (int i = 0; i < itl.getItemNewID(); i++) {
//			g1.addItem(itl.getNameOfNum(i));
//		}
//		this.add(g1);
//
//		JLabel g2 = new JLabel("掉落几率");
//		g2.setBounds(210, 370, 60, 20);
//		this.add(g2);
//
//		JTextField g3 = new JTextField("0");
//		g3.setBounds(270, 370, 130, 20);
//		this.add(g3);
//
//		JLabel h = new JLabel("怪物材质");
//		h.setBounds(210, 400, 60, 20);
//		this.add(h);
//
//		JTextField h1 = new JTextField();
//		h1.setBounds(210, 430, 190, 20);
//		h1.setEnabled(false);
//		h1.setDisabledTextColor(Color.black);
//		this.add(h1);
//
//		JButton h2 = new JButton("选择");
//		h2.setBounds(330, 400, 70, 20);
//		this.add(h2);
//
//		JLabel h3 = new JLabel("", JLabel.CENTER);
//		h3.setBounds(455, 340, 110, 110);
//		h3.setBorder(BorderFactory.createLineBorder(Color.black));
//		this.add(h3);
//
//		h2.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				if (filec.showOpenDialog(null) == filec.APPROVE_OPTION)
//					h1.setText(filec.getSelectedFile().getPath().replaceAll("\\\\", "/"));
//				h3.setIcon(new ImageIcon(h1.getText()));
//			}
//		});
//
//		JButton ok = new JButton("确认");
//		ok.setBounds(10, 580, 590, 18);
//		this.add(ok);
//
//		a1.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				FCMonster mo = monl.getMonsterOfID((String) a1.getSelectedItem());
//				if(mo == null) return;
//				nowSelectId = mo.getID();
//				a3.setText(mo.getName());
//				a5.setSelectedIndex(getTypeSelectedItem(mo.getType()));
//				h1.setText(mo.getPngUrl());
//				if (!h1.getText().equals("null") && h1.getText().length() > 1)
//					h3.setIcon(new ImageIcon(h1.getText()));
//				g3.setText(String.valueOf(mo.getDropPro()));
//				g1.setSelectedItem(mo.getDropItemID());
//				f1.setSelectedItem(mo.getGun3ActionID());
//				e1.setSelectedItem(mo.getGun2ActionID());
//				d1.setSelectedItem(mo.getGun1ActionID());
//				c1.setSelectedIndex(mo.getEventID() - 1);
//				shuxing[0].setText(String.valueOf(mo.getMoney()));
//				shuxing[1].setText(String.valueOf(mo.getBlood()));
//				shuxing[2].setText(String.valueOf(mo.getDefense()));
//				shuxing[3].setText(String.valueOf(mo.getDodge()));
//				shuxing[4].setText(String.valueOf(mo.getBloodAdd()));
//				shuxing[5].setText(String.valueOf(mo.getExperience()));
//				shuxing[6].setText(String.valueOf(mo.getGun1Defense()));
//				shuxing[7].setText(String.valueOf(mo.getGun1HurtOfCharacter()));
//				shuxing[8].setText(String.valueOf(mo.getGun1HurtOfTank()));
//				shuxing[9].setText(String.valueOf(mo.getGun1destruction()));
//				shuxing[10].setText(String.valueOf(mo.getGun1desdenfese()));
//				shuxing[11].setText(String.valueOf(mo.getGun2Defense()));
//				shuxing[12].setText(String.valueOf(mo.getGun2HurtOfCharacter()));
//				shuxing[13].setText(String.valueOf(mo.getGun2HurtOfTank()));
//				shuxing[14].setText(String.valueOf(mo.getGun2destruction()));
//				shuxing[15].setText(String.valueOf(mo.getGun2desdenfese()));
//				shuxing[16].setText(String.valueOf(mo.getGun3HurtOfCharacter()));
//				shuxing[17].setText(String.valueOf(mo.getGun3HurtOfTank()));
//				shuxing[18].setText(String.valueOf(mo.getGun3destruction()));
//				shuxing[19].setText(String.valueOf(mo.getGun3desdenfese()));
//				shuxing[20].setText(String.valueOf(mo.getAcidResistance()));
//				shuxing[21].setText(String.valueOf(mo.getParalysisResistance()));
//				shuxing[22].setText(String.valueOf(mo.getGasResistance()));
//				shuxing[23].setText(String.valueOf(mo.getSleepResistance()));
//				shuxing[24].setText(String.valueOf(mo.getFrozenResistance()));
//				shuxing[25].setText(String.valueOf(mo.getFireResistance()));
//				shuxing[26].setText(String.valueOf(mo.getSpeed()));
//				upgrade1.setSelectedItem(mo.getUpgradeMonsterID()==null?"null":mo.getUpgradeMonsterID());
//				keeptank1.setSelectedItem(mo.getKeepTank()==null?"null":mo.getKeepTank());
//				if(mo.getKeepFcItems().size() > 0) {
//					fightItem1a.setSelectedItem(mo.getKeepFcItems().get(0));
//					fightItem2a.setSelectedItem(mo.getKeepFcItems().get(1));
//					fightItem3a.setSelectedItem(mo.getKeepFcItems().get(2));
//					fightItem4a.setSelectedItem(mo.getKeepFcItems().get(3));
//				}
//			}
//		});
//
//		ok.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				if (a3.getText() != null && !a3.getText().equals("")) {
//					if (h1.getText() != null && !h1.getText().equals("")) {
//						if (!monl.isMonsterRepeat(a3.getText()) || !isnew) {
//							ArrayList<String> keepItems = new ArrayList<>();
//							keepItems.add(fightItem1a.getSelectedItem().toString());
//							keepItems.add(fightItem2a.getSelectedItem().toString());
//							keepItems.add(fightItem3a.getSelectedItem().toString());
//							keepItems.add(fightItem4a.getSelectedItem().toString());
//							if(isnew){
//								nowSelectId = stringToInt((String) a1.getSelectedItem());
//							}
//							monl.registerMonster(isnew, nowSelectId, a3.getText(),
//									type[a5.getSelectedIndex()], stringToInt(shuxing[0].getText()),
//									stringToInt(shuxing[1].getText()), stringToInt(shuxing[2].getText()),
//									stringToDouble(shuxing[3].getText()), stringToInt(shuxing[4].getText()),
//									stringToInt(shuxing[5].getText()), stringToInt(shuxing[6].getText()),
//									stringToInt(shuxing[7].getText()),stringToInt(shuxing[8].getText()),
//									stringToInt(shuxing[9].getText()),
//									stringToInt(shuxing[10].getText()), stringToInt(shuxing[11].getText()),
//									stringToInt(shuxing[12].getText()),
//									stringToInt(shuxing[13].getText()), stringToInt(shuxing[14].getText()),
//									stringToInt(shuxing[15].getText()),
//									stringToInt(shuxing[16].getText()), stringToInt(shuxing[17].getText()),
//									stringToInt(shuxing[18].getText()), stringToInt(shuxing[19].getText()),
//									stringToDouble(shuxing[20].getText()), stringToDouble(shuxing[21].getText()),
//									stringToDouble(shuxing[22].getText()), stringToDouble(shuxing[23].getText()),
//									stringToDouble(shuxing[24].getText()), stringToInt(shuxing[26].getText()),
//									stringToInt((String) c1.getSelectedItem()), (String) d1.getSelectedItem(),
//									(String) e1.getSelectedItem(), (String) f1.getSelectedItem(),
//									(String) g1.getSelectedItem(), stringToDouble(g3.getText()), h1.getText(),stringToDouble(shuxing[25].getText()),
//									(String) upgrade1.getSelectedItem(),(String) keeptank1.getSelectedItem(),keepItems);
//							dispose();
//							new FCTip("编辑怪物", "设置成功！");
//						} else
//							new FCTip("编辑怪物", "已存在该怪物！");
//					} else
//						new FCTip("编辑怪物", "材质不得为空！");
//				} else
//					new FCTip("编辑怪物", "名称不得为空！");
//			}
//		});
//
//		setVisible(true);
//	}
//
//	/**
//	 * String字符串转为int
//	 *
//	 * @param str
//	 * @return
//	 */
//	private int stringToInt(String str) {
//		if (str != null && !str.equals("")) {
//			return Integer.valueOf(str);
//		} else {
//			return 0;
//		}
//	}
//
//	/**
//	 * String字符串转为double
//	 *
//	 * @param str
//	 * @return
//	 */
//	private double stringToDouble(String str) {
//		if (str != null && !str.equals("")) {
//			return Double.valueOf(str);
//		} else {
//			return 0;
//		}
//	}
//
//	/**
//	 * 获得选中项
//	 *
//	 * @param t
//	 * @return
//	 */
//	private int getTypeSelectedItem(String t) {
//		for (int i = 0; i < type.length; i++) {
//			if (t.equals(type[i])) {
//				return i;
//			}
//		}
//		return 0;
//	}
}
